package server.core;

import java.util.Random;

/**
 * describe:有枪状态
 *
 * @author helloworldyu
 * @data 2018/3/23
 */
public class HasQuarterState extends AbstractState {
	Random randomWinner = new Random(System.currentTimeMillis());

	public HasQuarterState( GumballMachine machine ) {
		super(machine);
	}

	@Override
	public void insertQuarter() {
		System.out.println("你已经放入了一个硬币.");
	}

	@Override
	public void ejectQuarter() {
		System.out.println("退钱.");
		//切换状态
		gumballMachine.setState(gumballMachine.getNoQuarterState());
	}

	@Override
	public void turnCrank() {
		System.out.println("转动手柄成功，给你一个糖果.");
		//切换状态
		int winner = randomWinner.nextInt(10);
		if( (0==winner) && (gumballMachine.getCount()>1) ){
			gumballMachine.setState(gumballMachine.getWinnerState());
		}else {
			gumballMachine.setState(gumballMachine.getSoldingState());
		}
	}

	@Override
	public void dispense() {
		System.out.println("请先转动手柄!!!!!!!!");
	}
}